package Interfaz;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class FilePicker {
	String img=null;
	public void choosePicture(final EmpleadosWindow parent){
		
		final JFrame ventana = new JFrame("File manager V1");
		JPanel panel = new JPanel();
		JButton ok = new JButton(new ImageIcon(getClass().getResource("raw/nuevo.png")));
		
		ok.setBackground(Color.WHITE);
		ok.setBounds(570,25,48,48);
		//Inflate list
		
		//look for files
		File folder = new File(".");
		final String[] files = folder.list();
		String[][]filesMatrix = new String[(int) folder.length()][1];

		final JList list = new JList(files);
		JScrollPane scroll = new JScrollPane(list);
		//look for files end//
		
		//Inflate list END//
		ok.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(list.getSelectedIndex()!=-1){
					img = files[list.getSelectedIndex()];
					parent.setImageURL(img);
					System.out.println(parent.fotoURL);
					ventana.setVisible(false);
				}else{
					JOptionPane.showMessageDialog(null, "Debe seleccionar una imagen primero");
				}
			}
		});
		
		
		scroll.setBounds(5,5,500,400);
		
		ventana.add(scroll);
		ventana.add(ok);
		
		ventana.add(panel);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		ventana.setBounds(((d.width / 2) - 320), ((d.height / 2) - 240), 640, 480);
		panel.setBackground(Color.WHITE);
		ventana.setVisible(true);
	}
	
	public void choosePicture(final ReservaWindow parent){
		final JFrame ventana = new JFrame("File manager V1");
		JPanel panel = new JPanel();
		JButton ok = new JButton(new ImageIcon(getClass().getResource("raw/nuevo.png")));
		
		ok.setBackground(Color.WHITE);
		ok.setBounds(570,25,48,48);
		//Inflate list
		
		//look for files
		File folder = new File(".");
		final String[] files = folder.list();
		String[][]filesMatrix = new String[(int) folder.length()][1];

		final JList list = new JList(files);
		JScrollPane scroll = new JScrollPane(list);
		//look for files end//
		
		//Inflate list END//
		ok.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(list.getSelectedIndex()!=-1){
					img = files[list.getSelectedIndex()];
					//parent.setImageURL(img);
					//System.out.println(parent.fotoURL);
					ventana.setVisible(false);
				}else{
					JOptionPane.showMessageDialog(null, "Debe seleccionar una imagen primero");
				}
			}
		});
		
		
		scroll.setBounds(5,5,500,400);
		
		ventana.add(scroll);
		ventana.add(ok);
		
		ventana.add(panel);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		ventana.setBounds(((d.width / 2) - 320), ((d.height / 2) - 240), 640, 480);
		panel.setBackground(Color.WHITE);
		ventana.setVisible(true);
	}
	
	
public void escogerPicture(final ClientesWindow parent){
		
		final JFrame ventana = new JFrame("File manager V1");
		JPanel panel = new JPanel();
		JButton ok = new JButton(new ImageIcon(getClass().getResource("raw/nuevo.png")));
		
		ok.setBackground(Color.WHITE);
		ok.setBounds(570,25,48,48);
		//Inflate list
		
		//look for files
		File folder = new File(".");
		final String[] files = folder.list();
		String[][]filesMatrix = new String[(int) folder.length()][1];

		final JList list = new JList(files);
		JScrollPane scroll = new JScrollPane(list);
		//look for files end//
		
		//Inflate list END//
		ok.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(list.getSelectedIndex()!=-1){
					img = files[list.getSelectedIndex()];
					parent.setImageURL(img);
					System.out.println(parent.fotoURL);
					ventana.setVisible(false);
				}else{
					JOptionPane.showMessageDialog(null, "Debe seleccionar una imagen primero");
				}
			}
		});
		
		
		scroll.setBounds(5,5,500,400);
		
		ventana.add(scroll);
		ventana.add(ok);
		
		ventana.add(panel);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		ventana.setBounds(((d.width / 2) - 320), ((d.height / 2) - 240), 640, 480);
		panel.setBackground(Color.WHITE);
		ventana.setVisible(true);
	}
}
